package com.wuyangnju.lj.simulation.master.model.snapshot;

public class PlanDataSnapshot {
	private double sum;
	private double sumOfSquares;
	private long count;
	private double fixedVar;

	public PlanDataSnapshot(double sum, double sumOfSquares, long count) {
		this.sum = sum;
		this.sumOfSquares = sumOfSquares;
		this.count = count;
	}

	public PlanDataSnapshot(double sum, double sumOfSquares, long count,
			double fixedVar) {
		this.sum = sum;
		this.sumOfSquares = sumOfSquares;
		this.count = count;
		this.fixedVar = fixedVar;
	}

	public double getSum() {
		return sum;
	}

	public double getSumOfSquares() {
		return sumOfSquares;
	}

	public long getCount() {
		return count;
	}

	public double avg_X() {
		return sum / count;
	}

	public double var_S2() {
		return (sumOfSquares - sum * sum / count) / (count - 1);
	}

	public double deltaZ(PlanDataSnapshot o) {
		return 1 / (var_S2() / count + o.var_S2() / o.count);
	}

	public double deltaY(PlanDataSnapshot o) {
		return deltaZ(o) * (avg_X() - o.avg_X());
	}

	public double fixedDeltaZ(PlanDataSnapshot o) {
		return 1 / (fixedVar / count + o.fixedVar / o.count);
	}

	public double fixedDeltaY(PlanDataSnapshot o) {
		return fixedDeltaZ(o) * (avg_X() - o.avg_X());
	}
}
